package com.yanqu.road.server.cmd.activity.pawnshop;

import com.yanqu.road.entity.activity.pawnshop.PawnshopBidPrice;
import com.yanqu.road.entity.activity.pawnshop.PawnshopBidResult;
import com.yanqu.road.pb.activity.PawnshopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pawnshop.PawnshopModule;
import com.yanqu.road.server.pb.PawnshopPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_PAWNSHOP_USER_BID, desc = "请求玩家出价")
public class PawnshopUserBidCmd extends AbstractCommand {
	private int index;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		PawnshopProto.PawnshopUserBidReqMsg req = PawnshopProto.PawnshopUserBidReqMsg.parseFrom(packet.getBytes());
		index = req.getIndex();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		PawnshopProto.PawnshopUserBidRespMsg.Builder resp = PawnshopProto.PawnshopUserBidRespMsg.newBuilder();
		PawnshopBidResult bidResult = player.getModule(PawnshopModule.class).bid(index);
		ret = bidResult.getRet();
		resp.setRet(ret);
		if (ret == 0) {
			player.getModule(PawnshopModule.class);
			resp.setUserBid(bidResult.getUserBid());
            resp.setStatus(bidResult.getStatus());
			resp.setPatient(bidResult.getPatient());
			for (PawnshopBidPrice price : bidResult.getPriceList()) {
				resp.addPriceList(PawnshopPb.parseBidPrice(price));
			}
		}
		player.sendPacket(ClientProtocol.U_PAWNSHOP_USER_BID, resp);
	}

	@Override
	public void sendData(GamePlayer player) {

	}

}
